package com.designpattern.singleton.enumsingleton;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class EnumSingletonTest {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, IOException, ClassNotFoundException {
//        EnumSingleton instance = EnumSingleton.INSTANCE;
//        EnumSingleton instance1 = EnumSingleton.INSTANCE;
//        System.out.println(instance1==instance);

//        Constructor<EnumSingleton> declaredConstructor = EnumSingleton.class.getDeclaredConstructor(String.class, int.class);
//        declaredConstructor.setAccessible(true);
//        EnumSingleton instance = declaredConstructor.newInstance("INSTANCE",0);
//        System.out.println(instance);

        EnumSingleton instance = EnumSingleton.INSTANCE;
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("enumsingleton"));
        oos.writeObject(instance);
        oos.close();


        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("enumsingleton"));
        EnumSingleton enumSingleton = (EnumSingleton) ois.readObject();
        System.out.println(instance==enumSingleton);
        ois.close();
    }
}
